package server.data;

import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import util.Pair;

/**
 *
 * @author Danon
 */
public class Circuit<Router, Link> implements Serializable {
    
    private String name;
    private int id;
    private Map<Pair<Router, Router>, Link> linkMap;

    public Circuit(int id, String name) {
        this.name = name;
        this.id = id;
        linkMap = Collections.synchronizedMap(new LinkedHashMap<Pair<Router, Router>, Link>());
    }
    
    public void addEdge(Router v1, Router v2, Link l) {
        linkMap.put(new Pair<Router, Router>(v1, v2), l);
    }
    
    public Iterator<Pair<Router, Router>> chainIterator() {
        return linkMap.keySet().iterator();
    }
    
    public Link getLink(Pair<Router, Router> p) {
        return linkMap.get(p);
    }
    
    public Link getLink(Router v1, Router v2) {
        return getLink(new Pair<Router, Router>(v1, v2));
    }
    
    public void clear() {
        linkMap.clear();
    }
    
    public int size() {
        return linkMap.size();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
}
